home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 3: The Continuation / 17-Bit_The_Continuation_Disc.iso / amigan / amigan 20 / jimutils / printf.a < prev    next >
Text File  |  1994-01-27  |  8KB  |  136 lines

  1. *************************************************************************
  2. *                                                                       *
  3. *       fprintf - routine to call EXEC RawDoFmt to print to specified   *
  4. *                 output                                                *
  5. *                                                                       *
  6. *       Parameters:                                                     *
  7. *               D0 = output vector                                      *
  8. *                                                                       *
  9. *               A0 = ptr to format string                               *
  10. *               A1 = ptr to first parameter                             *
  11. *                                                                       *
  12. *       Return:                                                         *
  13. *               NONE                                                    *
  14. *                                                                       *
  15. *************************************************************************
  16.  
  17. fprintf::
  18.         movem.l a2/a3/a6,-(sp)
  19.         bra.s   pf1
  20.  
  21. *************************************************************************
  22. *                                                                       *
  23. *       printf - routine to call EXEC RawDoFmt to print to output       *
  24. *                                                                       *
  25. *       Parameters:                                                     *
  26. *               A0 = ptr to format string                               *
  27. *               A1 = ptr to first parameter                             *
  28. *                                                                       *
  29. *       Return:                                                         *
  30. *               Write return code (modified by buffering scheme)        *
  31. *                       -1 = ERROR .. Disk Full, Device not Avail, etc  *
  32. *                            call IoErr() to find specific error        *
  33. *                        0 = not defined                                *
  34. *                        n = number of characters written               *
  35. *                                                                       *
  36. *       Notes:                                                          *
  37. *               RawDoFmt requires 4 parameters:                         *
  38. *                       A0 = ptr to format string                       *
  39. *                       A1 = ptr to first parameter, stored in longword *
  40. *                            format, with numbers actually stored, and  *
  41. *                            pointers to strings stored instead of the  *
  42. *                            strings themselves                         *
  43. *                       A2 = ptr to routine to process characters as    *
  44. *                            they are generated by RawDoFmt             *
  45. *                       A3 = ptr to character buffer - convenient way   *
  46. *                            to pass a parameter to the routine whose   *
  47. *                            pointer is in A2                           *
  48. *                                                                       *
  49. *************************************************************************
  50.  
  51. printf::
  52.         movem.l a2/a3/a6,-(sp)
  53.         movem.l a0/a1,-(sp)             ; save parameters
  54.         move.l  DOSBase,a6              ; get base of dos.library
  55.         Call    Output                  ; find current output vector
  56.         movem.l (sp)+,a0/a1             ; restore parameters
  57. pf1:
  58.         move.l  d0,outvect              ; save output vector
  59.         move.l  _AbsExecBase,a6         ; get base of exec.library
  60.         lea     store(pc),a2            ; put address of 'store' routine in A2
  61.         lea     obuf,a3                 ; put address of buffer in A3
  62.         clr.b   -1(a3)                  ; and clear character count
  63.         Call    RawDoFmt                ; call "The Routine"
  64.         move.l  oerr,d0                 ; check the error code
  65.         bmi.s   1$                      ; real error?
  66.         move.l  totlen,d0               ; Nope.  Get # characters written
  67. 1$:
  68.         movem.l (sp)+,a2/a3/a6
  69.         rts
  70.  
  71. *************************************************************************
  72. *       store - the heart of the printf calls                           *
  73. *                                                                       *
  74. *       DESCRIPTION:                                                    *
  75. *               This routine is called by the RawDoFmt routine to       *
  76. *               process each character as it is generated.              *
  77. *                                                                       *
  78. *               Whereas I could have printed each character as it was   *
  79. *               generated, the Amiga is VERY slow on single character   *
  80. *               I/O, where it will print an entire line in about the    *
  81. *               same time as it takes to print one character.           *
  82. *                                                                       *
  83. *       Parameters:                                                     *
  84. *               RawDoFmt sends the character to process in D0.B, and    *
  85. *               buffer pointer you sent it in A3 is passed through to   *
  86. *               here unchanged, still in A3.                            *
  87. *                                                                       *
  88. *               When the RawDoFmt routine is through, it will send a    *
  89. *               NULL ($00).                                             *
  90. *                                                                       *
  91. *       Return:                                                         *
  92. *               NONE                                                    *
  93. *                                                                       *
  94. *       Notes:                                                          *
  95. *               You cannot change ANY register, except A3!!!            *
  96. *                                                                       *
  97. *************************************************************************
  98.  
  99. store:
  100.         movem.l d0-d7/a0-a6,-(sp)
  101.         moveq   #0,d1                   ; clear high portion of count
  102.         move.b  -1(a3),d1               ; move actual char count to low byte
  103.         tst.b   d0                      ; NULL from RawDoFmt?
  104.         beq.s   1$                      ; Yep, flush buffer & go home
  105.         move.b  d0,0(a3,d1.W)           ; store character in buffer
  106.         addq    #1,d1                   ; ...and add one to count
  107.         cmpi.b  #80,d1                  ; buffer full?
  108.         bne.s   3$                      ; no, go on
  109. 1$:
  110.         tst.l   oerr                    ; have we hit an error before?
  111.         bmi.s   2$                      ; yep, skip this attempt
  112.         move.l  DOSBase,a6              ; get base of dos.library
  113.         move.l  d1,d3                   ; put length in d3
  114.         move.l  outvect,d1              ; put output handle in d1
  115.         move.l  a3,d2                   ; and buffer address in d2
  116.         Call    Write                   ; and write it out!
  117.         move.l  d0,oerr                 ; store the return code
  118.         bmi.s   2$                      ; was it a real error?
  119.         add.l   d0,totlen               ; no, add to total chars written
  120. 2$:
  121.         moveq   #0,d1                   ; null count
  122. 3$:
  123.         move.b  d1,-1(a3)               ; store current count
  124.         movem.l (sp)+,d0-d7/a0-a6
  125.         rts
  126.  
  127.  
  128.         BSS
  129. DOSBase ds.l    1       ; storage for base address of 'dos.library'
  130. outvect ds.l    1       ; storage for output vector for 'store' routine
  131. totlen  ds.l    1       ; total number of characters written
  132. oerr    ds.l    1       ; storage for return code from most recent 'Write'
  133. olen    ds.b    1       ; current length of characters in output buffer
  134. obuf    ds.b    80      ; output buffer
  135.  
  136.